package com.cloud.jmmTest;

import java.util.Arrays;
import java.util.List;

public class TestAddSub {
    static int balance = 10;
    public static void withdraw() {
        balance += 5;
    }
    public static void deposit() {
        balance -= 5;
    }
    public static void main(String[] args) {
        List<Thread> threads = Arrays.asList(
                new Thread(TestAddSub::deposit),
                new Thread(TestAddSub::withdraw)
        );
        threads.forEach(Thread::start);
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(balance);
    }
}
